// 自定义分页
angular.module('com.dcos.app')
  .directive("customPager", [function(){
    return{
      restrict : 'EA',
      replace: true,
      scope: {
        page : '=',
        pageSize: '=',
        itemLength: '='
      },
      templateUrl: '../../directive/pagination/pagination.html',
      link: function(scope, element, attrs){
        element = $(element);

        scope.changePagesize = function(){
          scope.page = 1;
          scope.totalPage = Math.ceil(scope.itemLength / scope.pageSize);
          scope.pageArr = [];
          for(var i=1; i<=scope.totalPage; i++){
            scope.pageArr.push(i);
          }
        }

        scope.totalPage = Math.ceil(scope.itemLength / scope.pageSize);
        if(scope.page > scope.totalPage){
          scope.page = 1;
        }
        scope.pageArr = [];
        for(var i=1; i<=scope.totalPage; i++){
          scope.pageArr.push(i);
        }

        element.find(".previous-page").click(function(){
          scope.$apply(function(){
            if(scope.page != 1){
              scope.page -= 1;
            }
          });
        });

        element.find(".next-page").click(function(){
          scope.$apply(function(){
            if(scope.page != scope.totalPage){
              scope.page += 1;
            }
          });
        });
      }
    }
  }]);